-- module examples.MoreTailCall where

import Data.List (isPrefixOf)

match  ::  Int -> [Int] -> [Int] ->  Bool 
match n list1 list2 = match1 (take n (cycle [1,1,2,2,2])) where

    match1 [] = True
    match1 list | list1 `isPrefixOf` list = match2 (drop (length list1) list)
    match1 _  =  False

    match2 []  =  False 
    match2 list | list2 `isPrefixOf` list = match1 (drop (length list2) list)
    match2 _  =  False

--- should print true if argument is divisible by 5

main = putStrLn $ show $ match 12345670 [1,1] [2,2,2]